#!/usr/bin/env python

def clean(source):
	source = '\n'.join([line.rstrip() for line in source.split('\n')])
	return source

if __name__ == '__main__':
	import os

	for dirname, dirnames, filenames in os.walk('.'):
		filenames = filter(lambda x : x[-2:] == '.c',filenames)
		for filename in filenames:
			filepath = os.path.join(dirname,filename)
			print 'Cleaning',filepath

			with open(filepath,'r') as sourcefile:
				source = sourcefile.read()

			source = clean(source)

			with open(filepath,'w') as sourcefile:
				sourcefile.write(source)				
